// pages/pay/pay.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        goodsList:"",
        Address:"",
    },
    choosFun(){
        let _this = this
        wx.chooseAddress({
            success(res){
                // console.log(res);
                    _this.setData({
                        Address:res
                    })                    
            }
        })
        console.log(this.data.Address);
        
    },
    pays(){
	let date=new Date();
	//年
    let year=date.getFullYear();
    //月
    let month=date.getMonth()+1;
    //日
    let day=date.getDate();
    //时
    let hh=date.getHours();
    //分
    let m=date.getMinutes();
    let mm = m < 10? "0" + m : m
    //秒
    let s=date.getSeconds();
    let  ss =s<10?"0"+s:s;
    let rq=year+"-"+month+"-"+day+"-"+hh+":"+mm+":"+ss;
    let wholes = wx.getStorageSync('wholes');//全部订单数据
    let whole = wx.getStorageSync("GoodsCarLists");//购物车数据
    console.log("12344",wholes);
    whole.forEach((element) => {
        console.log(element);
        let{goodsImage,goodsName,goodsPrice,id,num} = element;
        let lists = {
            flag:2,
            ids:id,
            goodsName:goodsName,
            goodsImage:goodsImage,
            goodsPrice:goodsPrice,
            num:num,
            rq
        };
        wholes.splice(0,0,lists);
    });

        console.log("111",wholes);
        let goodsListlen =  (this.data.goodsList.length)//获取购物车的商品数量
        let wholeslen = (this.data.index-0 + 1); 
        console.log("索引",wholeslen);
        console.log("数量",goodsListlen);
        if(wholes){
             wholes.splice(wholeslen,goodsListlen);
            console.log("a",wholes);
            wx.setStorageSync("wholes",wholes);
        }else{
            wx.setStorageSync("wholes",who);
        }
    
    wx.setStorageSync('GoodsCarLists',"")
    // console.log(wholes);
        wx.navigateTo({
          url: '/pages/mycent/mycent',
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            index:options.index
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        var getCardata = wx.getStorageSync('GoodsCarLists');
        this.setData({
            goodsList: getCardata,
        })
        this.getTotal(); //计算总价格
    },
    // 计算总价格
    getTotal(){
        // 计算总价格
        let goodsList = this.data.goodsList;

        if(goodsList.length){
            let data = goodsList.reduce((total,item)=>{
                total = total + item.num * item.goodsPrice;
                return total;
            },0)
    
            
            this.setData({
                totalData:data
            })
        }
        

    },


    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})